import requests
from bs4 import BeautifulSoup as bs

url = 'http://www.xinfadi.com.cn/marketanalysis/0/list/1.shtml'
resp = requests.get(url=url)
print(resp.text)

# 指定 html 解析器
page = bs(resp.text, 'html.parser')

# 从 BeautifulSoup 中查数据
# find(标签名，属性=值): 找第一个
# find_all(标签名，属性=值): 找全部

# class 是 python 关键字，加上 _
table = page.find('table', class_='hq_table')
# 或者这种写法可不加 _
table = page.find('table', attrs={'class':'hq_table'})
print(table)

# 拿到所有数据
# [1:] 作切片去除表头
trs = table.find_all("tr")[1:]
for tr in trs:
    tds = tr.find_all("td")
    name = tds[0].text
    low = tds[1].text
    avg = tds[2].text
    high = tds[3].text
    size = tds[4].text
    kind = tds[5].text
    date = tds[6].text
    print(tds)